package com.w.picture.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.w.picture.api.aliyunai.model.ImageOutPaintingResponse;
import com.w.picture.mode.dto.picture.*;
import com.w.picture.mode.entity.Picture;
import com.w.picture.mode.entity.User;
import com.w.picture.mode.vo.PictureVO;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author wzp
 * @description 针对表【picture(图片)】的数据库操作Service
 * @createDate 2024-12-31 11:45:13
 */
public interface PictureService extends IService<Picture> {

    /**
     * 上传图片
     *
     * @param inputSource          输入源
     * @param type                 上传类型
     * @param pictureUploadRequest 图片上传请求信息
     * @param loginUser            登录用户
     * @return
     */
    PictureVO uploadPicture(Object inputSource, String type, PictureUploadRequest pictureUploadRequest, User loginUser);

    /**
     * 获取查询条件
     *
     * @param pictureQueryRequest 图片查询请求
     * @return queryWrapper
     */
    QueryWrapper<Picture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);

    /**
     * 获取图片信息vo
     *
     * @param picture 图片
     * @param request 请求
     * @return 图片信息vo
     */
    PictureVO getPictureVO(Picture picture, HttpServletRequest request);

    /**
     * 获取封装后的图片vo
     *
     * @param page    分页数据
     * @param request 请求
     * @return 图片vo分页信息
     */
    Page<PictureVO> getPictureVOPage(Page<Picture> page, HttpServletRequest request);

    /**
     * 校验图片信息
     *
     * @param picture 图片
     */
    void validPicture(Picture picture);

    /**
     * 图片审核
     *
     * @param pictureReviewRequest 图片审核请求
     * @param loginUser            登录用户
     */
    void doPictureReview(PictureReviewRequest pictureReviewRequest, User loginUser);

    void fillReviewParams(Picture picture, User loginUser);

    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest 图片批量上传请求
     * @param loginUser                   登录用户
     * @return 成功创建图片的数量
     */
    Integer uploadPictureByBatch(PictureUploadByBatchRequest pictureUploadByBatchRequest, User loginUser) throws UnsupportedEncodingException;

    void clearPictureFile(Picture picture);

    /**
     * 校验空间图片的权限
     *
     * @param loginUser
     * @param picture
     */
    void checkPictureAuth(User loginUser, Picture picture);

    /**
     * 删除图片
     * @param pictureId
     * @param loginUser
     */
    void deletePicture(long pictureId, User loginUser);

    void editPicture(PictureEditRequest pictureEditRequest, User loginUser);

    /**
     * 根据颜色搜索图片
     * @param spaceId 空间id
     * @param picColor 图片颜色
     * @param loginUser 登录用户
     * @return
     */
    List<PictureVO> searchPictureByColor(Long spaceId, String picColor, User loginUser);

    /**
     * 批量修改图片信息
     * @param pictureEditByBatchRequest
     * @param loginUser
     */
    void editPictureByBatch(PictureEditByBatchRequest pictureEditByBatchRequest, User loginUser);

    /**
     * 批量编辑图片分类和标签
     * 这个是优化版本:线程池 + 分批 + 并发 优化
     */
    void batchEditPictureMetadata(PictureEditByBatchRequest request, User loginUser);

    /**
     * 创建AI扩图任务
     * @param createPictureOutPaintingTaskRequest
     * @param loginUser
     * @return
     */
    ImageOutPaintingResponse createPictureOutPaintingTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, User loginUser);
}
